import { defineStore } from 'pinia'
import { getSiteInfo } from '@/utils/api/site'
import { filterCategory } from '@/utils/api/article'
import { ref } from 'vue'

export const useSiteStore = defineStore(
  'SiteStore',
  () => {
    const data = ref(null)
    const gen = async () => {
      data.value = await getSiteInfo()
      return data.value
    }
    const get = () => {
      return data.value
    }
    return {
      gen,
      get
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          key: 'MsgStore',
          storage: localStorage,
          paths: ['Message']
        }
      ]
    }
  }
)

export const useCategoryStore = defineStore(
  'CategoryStore',
  () => {
    const data = ref(null)
    const gen = async () => {
      data.value = await filterCategory()
      return data.value
    }
    const get = () => {
      return data.value
    }
    return {
      gen,
      get
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          key: 'CategoryStore',
          storage: sessionStorage,
          paths: ['Category']
        }
      ]
    }
  }
)
